<?php
class AttendanceIndexController  extends Zone_Action{
	
	public function fields(){
		$data = array(
			code	 => array(
				type 		=> 'TEXT',
				no_empty	=> true,
				form_label 	=> 'Số hiệu',
			),
            position  => array(
				type 		=> 'CHAR',
				no_empty	=> true,
				form_label 	=> 'Vị trí',
			),
            name	 => array(
				type 		=> 'TEXT',
				no_empty	=> true,
				form_label 	=> 'Tên người dùng',
			),
            othername	 => array(
				type 		=> 'TEXT',
				form_label 	=> 'Tên gọi khác',
			),
			birthday => array(
				type            => 'DATE',
				fix_value	=> change_date_format,
				form_label 	=> 'Ngày sinh',
				default_value	=>NULL
			),
			gender =>array(
				type		=>	'INT',
				form_label	=>	'Giới tính',
			),
			department_id	=> array(
				type 			=> 'INT',
				form_label 		=> 'Phòng ban'
			),
			functions	=> array(
				type 			=> 'TEXT',
				form_label 		=> 'Chức vụ',
				default_value 	=> NULL
			),

			email =>array(
				type			=> 'EMAIL',
				form_label		=> 'Email',
				default_value 	=> NULL
			),
			phone =>array(
				type			=> 'CHAR',
				form_label		=> 'Điện thoại',
				default_value 	=> NULL
			),
			updated_by_id =>array(
				type			=> 'NONE',
				default_value 	=> get_user_id()
			),
			date_updated =>array(
				type			=> 'NONE',
				default_value 	=> new Model_Expr('NOW()')
			)
		);
		return $data;
	}

	public function cvfields($default=NULL){
		$data = array(
			born_in	 => array(
				type 			=> 'TEXT',
				form_label 		=> 'Nơi sinh',
				default_value 	=> NULL
			),
			native_country => array(
				type			=> 'TEXT',
				form_label 		=> 'Nguyên quán',
				default_value 	=> NULL
			),
			nation	=> array(
				type 			=> 'TEXT',
				form_label 		=> 'Dân tộc',
				default_value 	=> NULL
			),
			religion =>array(
				type			=> 'TEXT',
				form_label		=> 'Tôn giáo',
				default_value 	=> NULL
			),
			inhabitant =>array(
				type			=>'TEXT',
				form_label		=>'Nơi đăng ký hộ khẩu',
				default_value 	=>NULL
			),
			residence =>array(
				type			=>'TEXT',
				form_label		=>'Nơi ở hiện tại',
				default_value 	=>NULL
			),
			date_recruit =>array(
				type			=>'DATE',
				fix_value	=> change_date_format,
				form_label		=>'Ngày tuyển dụng',
				default_value 	=>NULL
			),
			unit_recruit =>array(
				type			=>'TEXT',
				form_label		=>'Cơ quan tuyển dụng',
				default_value =>NULL
			),
            main_type_job =>array(
				type			=>'TEXT',
				form_label		=>'Công việc chính',
				default_value 	=>NULL
			),
            main_active =>array(
				type			=>'TEXT',
				form_label		=>'Sở trường công tác',
				default_value =>NULL
			),
            skill_common =>array(
				type			=>'TEXT',
				form_label		=>'Kỹ năng phổ thông',
				default_value =>NULL
			),
            skill_speciality_id =>array(
				type			=>'INT',
				form_label		=>'Kỹ năng chuyên môn',
				default_value   =>NULL
			),
            argue_politics =>array(
				type			=>'TEXT',
				form_label		=>'Lý luận chính trị',
				default_value =>NULL
			),
            skill_manage =>array(
				type			=>'TEXT',
				form_label		=>'Kỹ năng quản lý nhà nước',
				default_value =>NULL
			),
            skill_lang =>array(
				type			=>'TEXT',
				form_label		=>'Trình độ ngoại ngữ',
				default_value =>NULL
			),
            skill_lang_lv =>array(
				type			=>'CHAR',
				form_label		=>'Cấp bậc trình độ ngoại ngữ',
				default_value =>NULL
			),
            skill_info =>array(
				type			=>'TEXT',
				form_label		=>'Trình độ tin học',
				default_value   =>NULL
			),
            skill_info_lv =>array(
				type			=>'CHAR',
				form_label		=>'Cấp bậc trình độ CNTT',
				default_value   =>NULL
			),
            date_join_army =>array(
				type			=>'DATE',
				fix_value	=> change_date_format,
				form_label		=>'Ngày nhập ngũ',
				default_value =>NULL
			),
            date_out_army =>array(
				type			=>'DATE',
				fix_value	=> change_date_format,
				form_label		=>'Ngày xuất ngũ',
				default_value =>NULL
			),
            army_rank =>array(
				type			=>'TEXT',
				form_label		=>'Quân hàm',
				default_value =>NULL
			),
            identifier =>array(
				type			=>'TEXT',
				form_label		=>'Danh hiệu',
				default_value =>NULL
			),
            date_join_institute =>array(
				type			=>'DATE',
				fix_value	=> change_date_format,
				form_label		=>'Ngày gia nhập tổ chức chính trị xã hội',
				default_value =>NULL
			),
            reward =>array(
				type			=>'TEXT',
				form_label		=>'Phần thưởng',
				default_value =>NULL
			),
            status =>array(
				type			=>'TEXT',
				form_label		=>'Tình trạng sức khỏe',
				default_value =>NULL
			),
            tall =>array(
				type			=>'TEXT',
				form_label		=>'Chiều cao',
				default_value =>NULL
			),
            weight =>array(
				type			=>'TEXT',
				form_label		=>'Cân nặng',
				default_value =>NULL
			),
            blood_group =>array(
				type			=>'CHAR',
				form_label		=>'Nhóm máu',
				default_value =>NULL
			),
            discipline =>array(
				type			=>'TEXT',
				form_label		=>'Kỷ luật',
				default_value =>NULL
			),
            injury =>array(
				type			=>'TEXT',
				form_label		=>'Thương binh',
				default_value =>NULL
			),
            injury_policy =>array(
				type			=>'TEXT',
				form_label		=>'Chính sách',
				default_value =>NULL
			),
            identity_card =>array(
				type			=>'TEXT',
				form_label		=>'Số chứng minh thư nhân dân',
				default_value =>NULL
			),
            date_iden_sub =>array(
				type			=>'DATE',
				fix_value	=> change_date_format,
				form_label		=>'Ngày cấp',
				default_value =>NULL
			),
            safety_number =>array(
				type			=>'TEXT',
				form_label		=>'Số bảo hiểm xã hội',
			),
		);
		return $data;
	}
	
	public function workfields(){
		$data = array(
			work_date_from	 => array(
				type 		=> 'DATE',
				form_label 	=> 'Từ thời gian( Quá trình công tác )',
				fix_value	=> change_date_format,
				no_empty	=>true,
				default_value 	=>NULL
			),
			work_date_to => array(
				type => 'DATE',
				form_label 	=> 'Đến thời gian( Quá trình công tác )',
				no_empty	=>true,
				default_value 	=>NULL,
				fix_value	=> change_date_format
			),
			work_company	=> array(
				type 			=> 'TEXT',
				no_empty	=>true,
				form_label 		=> 'Đơn vị ( Quá trình công tác )'
			),
			work_wnotes =>array(
				type			=>'TEXT',
				form_label		=>'Mô tả( Quá trình công tác )',
				default_value 	=>NULL
			)
		);		
		return $data;
	}
	
	public function safields(){
		$data = array(
			skill_id	 => array(
				type 		=> 'INT',
				form_label 	=> 'Bằng cấp ( Quá trình lương )'
			),
            dateup	 => array(
				type 			=> 'DATE',
				form_label 		=> 'Ngày tăng lương ( Quá trình lương )',
				no_empty		=> true,
				fix_value		=> change_date_format, 
				default_value 	=> NULL
			),
            countb	 => array(
				type 		=> 'INT',
				form_label 	=> 'Bậc lương ( Quá trình lương )'
			),
			plussalary	=> array(
				type 			=> 'TEXT',
				form_label 		=> ' Phụ cấp ( Quá trình lương )',
				default_value 	=> 0
			)
		);
		return $data;
	}
 
	public function trainfields(){
		$data = array(
			train_date_from	 => array(
				type 			=> 'DATE',
				fix_value		=> change_date_format,
				no_empty		=> true,
				form_label 		=> 'Từ ngày ( Quá trình đào tạo )',
				default_value 	=> NULL
			),
			train_date_to => array(
				type 			=> 'DATE',
				form_label 		=> 'Đến ngày ( Quá trình đào tạo )',
				fix_value		=> change_date_format,
				default_value 	=> NULL
			),
			train_at	=> array(
				type 			=> 'TEXT',
				form_label 		=> 'Nơi đào tạo ( Quá trình đào tạo )',
				default_value 	=> NULL
			),
			train_level =>array(
				type			=>'INT',
				form_label		=>'Bằng cấp ( Quá trình đào tạo )',
				default_value 	=>NULL
			),
            train_level_type =>array(
				type			=>'CHAR',
				form_label		=>'Loại bằng cấp ( Quá trình đào tạo )',
				default_value 	=>NULL
			),
            train_desc =>array(
				type			=>'TEXT',
				form_label		=>'Mô tả',
				default_value 	=>NULL
			),

		);
		return $data;
	}
	
	public function contractfields(){
		$data = array(
			title	 => array(
				type 			=> 'CHAR',
				form_label 		=> 'Tên HĐ',
				no_empty		=> true,
				request_label	=> 'contract_title'				
			),
			code	 => array(
				type 			=> 'CHAR',
				form_label 		=> 'Tên HĐ',
				no_empty		=> true,
				request_label	=> 'contract_code'				
			),
			type_id	 => array(
				type 			=> 'INT',
				form_label 		=> 'Loại HĐ',
				no_empty		=> true,
				request_label	=> 'contract_type_id'				
			),
			date_reg	 => array(
				type 			=> 'DATE',
				fix_value		=> change_date_format,
				form_label 		=> 'Ngày ký HĐ',
				no_empty		=> true,
				default_value 	=> NULL,
				request_label	=> 'contract_date_reg'
			),
			date_start	 => array(
				type 			=> 'DATE',
				fix_value		=> change_date_format,
				form_label 		=> 'Ngày bắt đầu HĐ',
				default_value 	=> NULL,
				no_empty		=> true,
				request_label	=> 'contract_date_start'
			),
			date_finish	 => array(
				type 			=> 'DATE',
				fix_value		=> change_date_format,
				form_label 		=> 'Ngày kết thúc HĐ',
				default_value 	=> NULL,
				request_label	=> 'contract_date_finish'
			)
		);
		return $data;
	}	
	
	 public function govfields(){
		$data = array(
			family	 => array(
				type 		=> 'TEXT',
				form_label 	=> 'Thành phần gia đình',
				default_value 	=>NULL
			),
			job => array(
				type => 'TEXT',
				form_label 	=> 'Nghề nghiệp khi vào đảng',
				default_value 	=>NULL
			),
			main_work	=> array(
				type 			=> 'TEXT',
				form_label 		=> 'Công việc chính đang làm',
				default_value 	=>NULL
			),
			main_work_at =>array(
				type			=>'TEXT',
				form_label		=>'Tại',
				default_value 	=>NULL
			),
            date_gov_trial =>array(
				type			=>'DATE',
				form_label		=>'Ngày vào đảng',
				fix_value		=> change_date_format,
				default_value 	=>NULL
			),
            date_gov_trial_at =>array(
				type			=>'TEXT',
				form_label		=>' Tại chi bộ ',
				default_value 	=>NULL
			),
			date_gov_reg =>array(
				type			=>'DATE',
				form_label		=>' Ngày chính thức ',
				fix_value		=> change_date_format,
				default_value 	=>NULL
			),
			date_gov_reg_at =>array(
				type			=>'TEXT',
				form_label		=>' Tại chi bộ ',
				default_value 	=>NULL
			),
			per_take1 =>array(
				type			=>'TEXT',
				form_label		=>' người giới thiệu 1 ',
				default_value 	=>NULL
			),
			per_take1_at =>array(
				type			=>'TEXT',
				form_label		=>' Tại chi bộ ',
				default_value 	=>NULL
			),
			per_take2 =>array(
				type			=>'TEXT',
				form_label		=>' Người giới thiệu 2 ',
				default_value 	=>NULL
			),
			per_take2_at =>array(
				type			=>'TEXT',
				form_label		=>' Tại chi bộ ',
				default_value 	=>NULL
			),
			date_join =>array(
				type			=>'TEXT',
				form_label		=>'Mô tả',
				fix_value		=> change_date_format,
				default_value 	=>NULL
			),
			unit =>array(
				type			=>'TEXT',
				form_label		=>' Cơ quan tuyển dụng ',
				default_value 	=>NULL
			),
			fa_lietsy =>array(
				type			=>'CHAR',
				form_label		=>' Gia đình liệt sỹ ',
				default_value 	=>NULL
			),
			fa_cocong =>array(
				type			=>'CHAR',
				form_label		=>' Gia đình có công ',
				default_value 	=>NULL
			),

		);
		return $data;
	}

	public function govacfields(){
		$data = array(
			date_govs_from	 => array(
				type 			=> 'DATE',
				form_label 		=> 'Từ ngày ( Quá trình sinh hoạt Đảng )',
				fix_value		=> change_date_format, 
				no_empty		=> true,
				default_value 	=> NULL
			),
			date_govs_to => array(
				type		 	=> 'DATE',
				form_label 		=> 'Đến ngày( Quá trình sinh hoạt Đảng )',
				fix_value		=> change_date_format, 
				default_value 	=> NULL
			),
			act_at => array(
				type => 'TEXT',
				form_label 		=> 'Sinh hoạt tại chi bộ ( Quá trình sinh hoạt Đảng )',
				default_value 	=> NULL
			),
			act_desc	=> array(
				type 			=> 'TEXT',
				form_label 		=> 'Mô tả ( Quá trình sinh hoạt Đảng )',
				default_value 	=> NULL
			)
		);

		return $data;
	}

	public function initAction(){
		$departments = $this->Model->fetchAll("SELECT 
				`a`.*,
				`b`.`username`,
				`b`.`ID` as `user_id`
			FROM `departments` as `a`
			LEFT JOIN `users` as `b` 
				ON `a`.`created_by_id`=`b`.`ID`
            WHERE `a`.`parent_id`<>0
                AND `a`.`parent_id` IS NOT NULL
			ORDER BY `ID`");
		
		$departments2 = $this->Model->fetchAll("SELECT 
				`a`.*
			FROM `departments` as `a`
			ORDER BY `ord`");
			
		$this->set(array(
			departments			=> $departments2,
			setting				=> $this->Model->fetchRow("SELECT * FROM `personnels_settings` LIMIT 1"),
			side_departments	=> $departments,
            salary_params       => $this->Model->fetchAll("SELECT * FROM `personnels_salary_params`")
		));
	}

	public function indexAction(){
		$user_id = get_user_id();
		$vars   = array();
		$where  = array("`a`.`is_draft`='no'");
		
		$order_by = "ORDER BY `a`.`ID` DESC";

		$current_page = max(getInt('p',1),1);
		
		$range_page = max(10,(int)$this->getConfig('user.page',20));
		if( isset($_REQUEST['p']) ){
			$vars['p'] = $current_page;
		}

		if( isset($_REQUEST['rp'])){
			$vars['rp'] = $range_page;
		}
		
		$limit = "LIMIT ".($current_page-1)*$range_page.",$range_page";

		$field_order = array('name','department_id','functions','birthday','phone','gender');
		foreach( $field_order as $f ){
			if( get('order_by') == $f ){
				$order_by = "ORDER BY $f ". ( get('order_type') == 'desc' ? 'desc' : 'asc');
				$vars['order_by'] = $f;
				if( get('order_type') == 'desc' ){
					$vars['order_by']='desc';
				}
				break;
			}
		}

		if( ( $word = get('s',NULL) ) != NULL ){
			$search = array();
			foreach( $field_order as $f ){
				$search[]="`a`.`$f` LIKE '%$word%'";
			}
			
			$where[] = '('.implode(' OR ',$search).')';
			$vars['s'] = $word;	
		}

		if( ( $dep_id = getInt('dep_id',0)) != 0   ){
			$vars['dep_id'] = $dep_id;
			$where[]="`a`.`department_id` = '$dep_id'";
		}
		
		$where = implode(' AND ',$where);
		// die("SELECT `a`.*,`b`.`title` as `depart_name`
			// FROM `personnels` as `a`
				// LEFT JOIN `departments` as `b` 
					// ON `b`.`ID`=`a`.`department_id`
			// WHERE $where $order_by $limit");
		$total = $this
			->Model
			->fetchOne("SELECT COUNT(*) as `total` 
				FROM `personnels` as `a` WHERE $where ");

		$posts = $this->Model->fetchAll("SELECT `a`.*,`b`.`title` as `depart_name`
			FROM `personnels` as `a`
				LEFT JOIN `departments` as `b` 
					ON `b`.`ID`=`a`.`department_id`
			WHERE $where $order_by $limit");

		$a = $vars;
		unset($a['p']);

		$page = page_ajax('#Personnel?'.to_query_configs($a).'&p=', $total , $range_page, $current_page);

		$this->set(array(
			user_id =>get_user_id(),
			page		=> $page,
			total		=> $total,
			vars		=> $vars,
			personnel	=> $posts
		));
	}
	
	public function salaryupAction(){
		
		$dep_id = getInt('dep_id',0);

		$user_id = get_user_id();
		$vars = array();
		$WHERE = array();
		$order_by = "ORDER BY `a`.`ID` DESC";

		$current_page = max(getInt('p',1),1);
		$range_page = max(10,(int)$this->getConfig('user.page',20));
		if( isset($_REQUEST['p']) ){
			$vars['p'] = $current_page;
		}

		if( isset($_REQUEST['rp'])){
			$vars['rp'] = $range_page;
		}
		$limit = "LIMIT ".($current_page-1)*$range_page.",$range_page";

		$field_order = array('name','depart_name','functions','birthday','phone');
		foreach( $field_order as $f ){
			if( get('order_by') == $f ){
				$order_by = "ORDER BY $f ". ( get('order_type') == 'desc' ? 'desc' : 'asc');
				$vars['order_by'] = $f;
				if( get('order_type') == 'desc' ){
					$vars['order_by']='desc';
				}
				break;
			}
		}
		if($dep_id!=0){
			$vars['dep_id'] = $dep_id;
			$condition = " and `a`.`department_id`='$dep_id'";
			$titleDep = $this->Model->fetchRow("SELECT * FROM `departments` WHERE `ID`='$dep_id'");
			$this->view->titleDep = $titleDep['title'];
		}

		$total = $this->Model->fetchOne("SELECT COUNT(*) as `total` FROM `personnels` as `a` WHERE `a`.`is_draft`='no' $condition");

		if( getInt('phase') == 1 ){
			$time = date('Y').'-06-30';
			$vars['phase'] = 1;
		}else{
			$time = date('Y').'-12-31';
			$vars['phase'] = 2;
		}
		
		$posts = $this->Model->fetchAll("
				SELECT * FROM ( SELECT `a`.*, 
						MAX(`b`.`dateup`) as `date_salary`,
						`c`.`stone`,
						`d`.`title` as `depart_name`,
						`b`.`plussalary` as `plussalary`,
						`b`.`plussalary` + CAST( ((`b`.`countb`-1)*`c`.`subsalary` + `c`.`salary`) as DECIMAL(5,2) ) as `old_param`,
						`b`.`plussalary` + CAST( (`b`.`countb`*`c`.`subsalary` + `c`.`salary` ) as DECIMAL(5,2) ) as `new_param`,
						STR_TO_DATE(PERIOD_ADD( date_format(MAX(`b`.`dateup`),'%Y%m'), `c`.`stone`*12 ),'%Y%m') as `date_change` 	
					FROM `personnels_salarys` as `b`
					LEFT JOIN `personnels` as `a`
						ON `a`.`ID`=`b`.`personnel_id`
					LEFT JOIN `personnels_salary_params` as `c`
						ON `b`.`skill_id`=`c`.`ID`
					LEFT JOIN `departments` as `d` 
						ON `d`.`ID`=`a`.`department_id`
					WHERE `a`.`is_draft`='no'	
				GROUP BY `b`.`personnel_id`	) as `k`	
				WHERE 
					PERIOD_DIFF(date_format('$time', '%Y%m'), 
						date_format(`date_salary`, '%Y%m'))/12 >= `stone`");
	
		$a = $vars;
		unset($a['p']);

		$page = page_ajax('#Personnel?'.to_query_configs($a).'&p=', $total , $range_page, $current_page);

		$this->set(array(
			user_id =>get_user_id(),
			page	=> $page,
			total	=> $total,
			vars	=> $vars,
			posts	=> $posts
		));
	}	

	public function uploadAction(){
		$this->removeLayout();
		$post_id = getInt('ID',0);
		$post = $this->Model->fetchRow("SELECT * FROM `personnels` WHERE `ID`='$post_id'");
		
		if( !$post ){
			return $this->setJson(array(
				alert => 'Bản ghi không tồn tại hoặc đã bị xóa'
			));
		}
		
		if( isPost()){
			loadClass('ZData');
			$f = new ZData();
			$f->addField(array(
				file => array(
					type 		=> 'FILE',
					path		=> 'files/personnel/',
					no_empty	=> true
				),
			));
			$data = $f->getData();
			if( is_array( $data ) ){
				$file = $data['file'];
				$data1 = array(
					personnel_id    => $post_id,
					name			=> $file[0],
					type			=> $file[1],
					size			=> $file[2],
					filename		=> $file[3]
				);
				$this->Model->insert('personnels_files',$data1);

				$file_id = $this->Model->lastId();
				return $this->setJSON(array(
					content	=> "<div class='x-file-info'><input checked type='checkbox' name='files[]' value='$file_id'/>
								<a href='".ctrUrl($this)."/File?ID=$file_id' target='_blank'>{$file[3]} {$file[2]} KB	</a>
								</div>"
				));
			}else{
				return $this->setJSON(array(
					alert => error($data)
				));
			}
		}
	}

	public function addAction(){
		$user_id = get_user_id();
		
		$post = $this
			->Model
			->fetchRow("SELECT * FROM `personnels` WHERE `is_draft`='yes' AND `created_by_id`='$user_id' LIMIT 1");			
					
		$post_id = $post['ID'];			
		if( !$post ){
			$this->Model->insert('personnels',array(
				is_draft		=> 'yes',
				created_by_id	=>	get_user_id(),
				date_created 	=> 	new Model_Expr('NOW()')
			));
			
			$post_id = $this->Model->lastId();				
		}
		
		$this->set(array(
			ID				=> $post_id,
			post 			=> $post,
			skills_sp       => $this->Model->fetchAll("SELECT * FROM `personnels_degrees` ORDER BY `title`"),
			contract_type   => $this->Model->fetchAll("SELECT * FROM `personnels_contract_types` ORDER BY `title`")
		));		
		
		if(isPost()){
			loadClass('ZData');
			$f = new ZData();
			$f->addfields( $this->fields());

			$data = $f->getData();
			if( !is_array($data) ){
				return $this->setJSON(array(
					alert	=> $data
				));
			}						
			
			//general information
			$f = new ZData();
			$f->addfields( $this->cvfields());
			$data1 = $f->getData();

			if( !is_array($data) ){
				return $this->setJSON(array(
					alert	=> $data1
				));
			}

			//Salary
			$data2 = array();
			foreach(get('dateup',array(),true) as $k => $v ){
				$f = new ZData();
				$f->addfields( $this->safields());
				$f->setIndexItem($k);
				$a = $f->getData();
				if(!is_array($a)){
					return $this->setJSON(array(
						alert	=> $a
					));				
				}
				$data2[]=$a;
			}
			
			
			//Degree
			$data3 = array();
			foreach(get('train_date_from',array(),true) as $k => $v ){
				$f = new ZData();
				$f->addfields( $this->trainfields());
				$f->setIndexItem($k);
				$a = $f->getData();
				if(!is_array($a)){
					return $this->setJSON(array(
						alert	=> $a
					));
				}	
				$data3[] = $a;					
			}			
			
			//Contract
			$data4=array();
			foreach(get('contract_title',array(),true) as $k => $v ){
				$f = new ZData();
				$f->addfields( $this->contractfields());
				$f->setIndexItem($k);
				$a = $f->getData();				
				
				if(!is_array($a)){
					return $this->setJSON(array(
						alert	=> $a
					));
				}	
				$data4[] = $a;					
			}			
				
			//work history	
			$data5 = array();
			foreach(get('work_date_from',array(),true) as $k => $v ){
				$f = new ZData();
				$f->addfields( $this->workfields());
				$f->setIndexItem($k);
				$a = $f->getData();
				
				if(!is_array($a)){
					return $this->setJSON(array(
						alert	=> $a
					));
				}	
				$data5[] = $a;				
			}
			
			//govs			
			$f = new ZData();
			$f->addfields( $this->govfields());
			$data6 = $f->getData();
			
			if(!is_array($data)){
				return $this->setJSON(array(
					alert	=> $data6
				));			
			}			

			$data7 = array();	
			foreach(get('date_govs_from',array(),true) as $k => $v ){
				$f = new ZData();
				$f->addfields( $this->govacfields());			
				$f->setIndexItem($k);
				$a = $f->getData();
				
				if(!is_array($data)){				
					return $this->setJSON(array(
						alert	=> $data6
					));
				}
				$data7[]=$a;
			}


			/* update if all validation are successfull */
			$data['is_draft']	   = 'no';
			$data['created_by_id'] = get_user_id();
			$data['date_created']  = new Model_Expr('NOW()');

			$this->Model->update('personnels', $data, " `ID`='$post_id' ");
			
			//clean up
			$this->Model->delete('personnels_salarys',"`personnel_id`='$post_id'");
			$this->Model->delete('personnels_trainings',"`personnel_id`='$post_id'");
			$this->Model->delete('personnels_contracts',"`personnel_id`='$post_id'");
			$this->Model->delete('personnels_activities',"`personnel_id`='$post_id'");
			$this->Model->delete('personnels_govs',"`personnel_id`='$post_id'");
			$this->Model->delete('personnels_govs_activities',"`personnel_id`='$post_id'");


			$data1['personnel_id'] = $post_id;
			if( $this->Model->fetchRow("SELECT * FROM `personnels_cvs` WHERE `personnel_id`='$post_id'") ){
				$this->Model->update('personnels_cvs', $data1, "`personnel_id`='$post_id'");
			}else{	
				$this->Model->insert('personnels_cvs',$data1);
			}						
			
			foreach( $data2 as $v ){
				$v['personnel_id'] = $post_id;
				$this->Model->insert('personnels_salarys',$v);
			}
			
			foreach($data3 as $v ){
				$v['personnel_id'] = $post_id;
				$this->Model->insert('personnels_trainings',$v);
			}
			
			//Contract
			foreach($data4 as $v ){
				$v['personnel_id'] = $post_id;
				$this->Model->insert('personnels_contracts',$v);
			}			
			
			// work history
			foreach($data5 as $v ){
				$v['personnel_id'] = $post_id;
				$this->Model->insert('personnels_activities',$v);
			}
			
			//govs			
			$data6['personnel_id'] = $post_id;				
			$this->Model->insert('personnels_govs',$data6);
			
			foreach($data7 as $v ){
				$v['personnel_id'] = $post_id;					
				$this->Model->insert('personnels_govs_activities',$v);
			}
			
			$files_selected = get('files',array(),true);
			$files = $this->Model->fetchAll("SELECT * FROM `personnels_files` WHERE `personnel_id`='$post_id'");
			foreach( $files as $f ){
				if( !in_array( $f['ID'], $files_selected ) ){
					$this->Model->delete('personnels_files',"`ID`='{$f['ID']}'");
					@unlink("files/personnel/{$f['name']}");
				}
			}			
			
			return $this->setJSON(array(
				redirect => '#Personnel/Index/View?ID='.$post_id
			));
		}
	}

	public function editAction(){
		$post_id = getInt('ID',0);
		
		$post = $this->Model->fetchRow("SELECT * FROM `personnels` WHERE `is_draft`='no' AND `ID`='$post_id'");
		
		if( !$post ){
			return $this->setJson(array(
				content => error('Bản ghi không tồn tại hoặc đã bị xóa')
			));
		}	
		
		$general 		= $this->Model->fetchRow("SELECT * FROM `personnels` WHERE `ID`='$post_id'");
		$cvs 	 		= $this->Model->fetchRow("SELECT * FROM `personnels_cvs` WHERE `personnel_id`='$post_id'");
		$salary  		= $this->Model->fetchAll("SELECT 
				`a`.*,
				`b`.`title`,
				`b`.`salary` as `initsalary`,	
				`b`.`subsalary`
			FROM `personnels_salarys` as `a`
			LEFT JOIN `personnels_salary_params` as `b`
			ON `b`.`ID`=`a`.`skill_id`	
			WHERE `a`.`personnel_id`='$post_id'");
			
		$files  		= $this->Model->fetchAll("SELECT * FROM `personnels_files` WHERE `personnel_id`='$post_id'");
		$train 	 		= $this->Model->fetchAll("SELECT `a`.*,`b`.`title` as `train_level_title`  
			FROM `personnels_trainings` as `a`
			LEFT JOIN `personnels_degrees` as `b`
				ON `a`.`train_level`=`b`.`ID`
			WHERE `a`.`personnel_id`='$post_id'");
		
		$work_active 	= $this->Model->fetchAll("SELECT * FROM `personnels_activities` WHERE `personnel_id`='$post_id'");
		
		$govs 	 		= $this->Model->fetchRow("SELECT * FROM `personnels_govs` WHERE `personnel_id`='$post_id'");
		$gov_act 		= $this->Model->fetchAll("SELECT * FROM `personnels_govs_activities` WHERE `personnel_id`='$post_id'");
		$contracts = $this->Model->fetchAll("SELECT `a`.*,`b`.`title` as `type` 
			FROM `personnels_contracts` as `a` 
			LEFT JOIN `personnels_contract_types` as `b`
				ON `a`.`type_id` = `b`.`ID`
			WHERE `a`.`personnel_id`='$post_id' ORDER BY `a`.`date_reg`");
			
		$this->set(array(
			post		=>  $post,
			general 	=>	$general,
			cvs 		=>	$cvs,
			salary 		=>	$salary,
			train 		=>	$train,
			work_active =>	$work_active,
			govs		=>	$govs,
			govacts		=>	$gov_act,
			files		=>  $files,
			contracts	=>  $contracts,
			skills_sp       => $this->Model->fetchAll("SELECT * FROM `personnels_degrees` ORDER BY `title`"),
			contract_type   => $this->Model->fetchAll("SELECT * FROM `personnels_contract_types` ORDER BY `title`")
		));
				
		if(isPost()){
			loadClass('ZData');
			$f = new ZData();
			$f->addfields( $this->fields());

			$data = $f->getData();
			if( !is_array($data) ){
				return $this->setJSON(array(
					alert	=> $data
				));
			}						
			
			//general information
			$f = new ZData();
			$f->addfields( $this->cvfields());
			$data1 = $f->getData();

			if( !is_array($data) ){
				return $this->setJSON(array(
					alert	=> $data1
				));
			}

			//Salary
			$data2 = array();
			foreach(get('dateup',array(),true) as $k => $v ){
				$f = new ZData();
				$f->addfields( $this->safields());
				$f->setIndexItem($k);
				$a = $f->getData();
				if(!is_array($a)){
					return $this->setJSON(array(
						alert	=> $a
					));				
				}
				$data2[]=$a;
			}
			
			
			//Degree
			$data3 = array();
			foreach(get('train_date_from',array(),true) as $k => $v ){
				$f = new ZData();
				$f->addfields( $this->trainfields());
				$f->setIndexItem($k);
				$a = $f->getData();
				if(!is_array($a)){
					return $this->setJSON(array(
						alert	=> $a
					));
				}	
				$data3[] = $a;					
			}			
			
			//Contract
			$data4=array();
			foreach(get('contract_title',array(),true) as $k => $v ){
				$f = new ZData();
				$f->addfields( $this->contractfields());
				$f->setIndexItem($k);
				$a = $f->getData();				
				
				if(!is_array($a)){
					return $this->setJSON(array(
						alert	=> $a
					));
				}	
				$data4[] = $a;					
			}			
				
			//work history	
			$data5 = array();
			foreach(get('work_date_from',array(),true) as $k => $v ){
				$f = new ZData();
				$f->addfields( $this->workfields());
				$f->setIndexItem($k);
				$a = $f->getData();
				
				if(!is_array($a)){
					return $this->setJSON(array(
						alert	=> $a
					));
				}	
				$data5[] = $a;				
			}
			
			//govs			
			$f = new ZData();
			$f->addfields( $this->govfields());
			$data6 = $f->getData();
			
			if(!is_array($data)){
				return $this->setJSON(array(
					alert	=> $data6
				));			
			}			

			$data7 = array();	
			foreach(get('date_govs_from',array(),true) as $k => $v ){
				$f = new ZData();
				$f->addfields( $this->govacfields());			
				$f->setIndexItem($k);
				$a = $f->getData();
				
				if(!is_array($a)){				
					return $this->setJSON(array(
						alert	=> $a
					));
				}
				$data7[]=$a;
			}			
			
			/* update if all validation pass */
			$this->Model->update('personnels', $data, " `ID`='$post_id' ");

			$data1['personnel_id'] = $post_id;
			if( $this->Model->fetchRow("SELECT * FROM `personnels_cvs` WHERE `personnel_id`='$post_id'") ){
				$this->Model->update('personnels_cvs', $data1, "`personnel_id`='$post_id'");
			}else{	
				$this->Model->insert('personnels_cvs',$data1);
			}						
			
			foreach( $data2 as $v ){
				$v['personnel_id'] = $post_id;
				$this->Model->insert('personnels_salarys',$v);
			}
			
			foreach($data3 as $v ){
				$v['personnel_id'] = $post_id;
				$this->Model->insert('personnels_trainings',$v);
			}
			
			//Contract
			foreach($data4 as $v ){
				$v['personnel_id'] = $post_id;
				$this->Model->insert('personnels_contracts',$v);
			}			
			
			// work history
			foreach($data5 as $v ){
				$v['personnel_id'] = $post_id;
				$this->Model->insert('personnels_activities',$v);
			}
			
			//govs			
			$data6['personnel_id'] = $post_id;				
			if( $this->Model->fetchRow("SELECT * FROM `personnels_govs` WHERE `personnel_id`='$post_id'") ){
				$this->Model->update('personnels_govs',	$data6, "`personnel_id`='$post_id'");
			}else{	
				$this->Model->insert('personnels_govs',$data6);
			}
			
			foreach( $data7 as $v ){
				$v['personnel_id'] = $post_id;					
				$this->Model->insert('personnels_govs_activities',$v);
			}
			
			$files_selected = get('files',array(),true);			
			foreach( $files as $f ){
				if( !in_array( $f['ID'], $files_selected ) ){
					$this->Model->delete('personnels_files',"`ID`='{$f['ID']}'");
					@unlink("files/personnel/{$f['name']}");
				}
			}			
			
			return $this->setJSON(array(
				redirect => '#Personnel/Index/View?ID='.$post_id
			));             
		}
	}

	function department_map( $items  ){
		foreach( $items as $k => $item ){
			$t = true;
			for( $i=0; $i < count($items) ;$i++  ){
				if( $item['parent_id'] == $items[$i]['ID'] ){
					$t=false;
					break;
				}
			}
			if( $t ){
				$items[$k]['parent_id'] = '0';
			}
		}
		return $this->department_map_recruise($items);
	}

	function department_map_recruise( $items, $parent_id='0', $c=0 ){
		//limit deep
		if( $c > 10 ) return "";
		$html="";
		foreach( $items as $k => $a ){
			if( $a['parent_id'] == $parent_id ){
				$html .= "
					<li class='personnel-sub-link'>
						<a".($parent_id==0?' style="color:red;font-weight:bold"':'').">".str_repeat(" + + ",$c)." {$a['title']}</a>
					</li>";
				unset( $items[$k] );
				$html .= $this->department_map_recruise( $items, $a['ID'], $c+1 );
			}
		}
		return $html;
	}

	public function printcvAction(){
		$this->removeLayout();
		$post_id = getInt('ID',0);
		$post = $this->Model->fetchRow("
			SELECT `a`.*,`b`.*,`c`.*,`d`.`title` as `skill_speciality_title` FROM `personnels` as `a` 
				LEFT JOIN `personnels_cvs` as `b` ON `b`.`personnel_id`=`a`.`ID`
				LEFT JOIN `personnels_govs` as `c` ON `c`.`personnel_id`=`a`.`ID`
				LEFT JOIN `personnels_degrees` as `d` ON `d`.`ID`=`b`.`skill_speciality_id`
			WHERE `a`.`ID`='$post_id'");
			
		$training = $this->Model->fetchAll("SELECT * FROM `personnels_trainings` as `a` WHERE `personnel_id`='$post_id'");
		$active = $this->Model->fetchAll("SELECT * FROM `personnels_activities` as `a` WHERE `personnel_id`='$post_id'");
		
		$this->set(array(
			post 		=> $post,
			training 	=> $training,
			active 		=> $active
		));
	}
	
	public function printgovAction(){
		$this->removeLayout();
		$post_id = getInt('ID',0);
		$govs = $this->Model->fetchRow("
			SELECT `a`.*,`b`.*,`c`.*,`d`.`title` as `skill_speciality_title` 
			FROM `personnels_govs` as `a` 
				LEFT JOIN `personnels` as `b` ON `b`.`ID` = `a`.`personnel_id`
				LEFT JOIN `personnels_cvs` as `c` ON `c`.`personnel_id` = `a`.`personnel_id`
				LEFT JOIN `personnels_degrees` as `d` ON `d`.`ID`=`c`.`skill_speciality_id`
			WHERE `a`.`personnel_id`='$post_id'
		");
		$govs_acts = $this->Model->fetchAll("SELECT * FROM `personnels_govs_activities` WHERE `personnel_id`='$post_id'");
		$this->set(array(
			govs =>$govs,
			govs_acts =>$govs_acts		
		));
	}
	
	public function photoAction(){
		$this->removeLayout();
		if( isPost()){
			$personnel_id = getInt('ID',0);
			loadClass("ZData");
			$f = new ZData();
			$f->addField(array(
				photo => array(
					type 		=> 'IMAGE',
					path		=> 'files/personnel/',
					return_name	=> true,
					resize		=> array(150,200),
					max_size	=> 1024*3
				),
			));
			
			$data = $f->getData();			
			
			if( !is_array( $data ) ){
				return $this->setJSON(array(
					alert => $data
				));
			}
						
			$post_id = get('ID');
			$post = $this
			->Model
			->fetchRow("SELECT * FROM `personnels` WHERE `ID`='$post_id'");
			
			if(!$post){
				return $this->setJSON(array(
					alert => 'Bản ghi không tồn tại hoặc đã bị xóa'
				));
			}

			if( $post['photo'] ){
				@unlink("files/personnel/{$post['photo']}");
			}	
		
			$this->Model->update("personnels",$data,"`ID`='$post_id'");

			return $this->setJSON(array(
				callback => "(function(){
					$('img.personnel-photo')
						.each(function(){
							this.src = baseURL+'/files/personnel/{$data['photo']}?'+(new Date()).getTime();
						})
				})()"
			));
		}
	}
	
	public function viewAction(){ 
		$post_id = getInt('ID',0);
		$post = $this->Model->fetchRow("
			SELECT `a`.*,`b`.`title` as `department_name`,`c`.`username` as `updated_by_name`,`c`.`is_deleted` as `updated_is_deleted`
				FROM `personnels` AS `a` 
					LEFT JOIN `departments` as `b` ON `a`.`department_id`=`b`.`ID`
					LEFT JOIN `users` as `c` ON `c`.`ID`=`a`.`created_by_id`
			WHERE `a`.`ID`='$post_id'");
		
		if( !$post ){
			return $this->setContent(error('Bản ghi không tồn tại hoặc đã bị xóa'));
		}
		
		$cvs = $this->Model->fetchRow("
			SELECT `a`.*,`b`.`title`  as `skill_speciality_title`
				FROM `personnels_cvs` as `a` 
				LEFT JOIN `personnels_degrees` as `b` ON `b`.`ID`=`a`.`skill_speciality_id`
			WHERE `a`.`personnel_id`='$post_id'
		");
		$salary = $this->Model->fetchAll("
			SELECT `a`.*,
					`b`.`title`,
					`b`.`subsalary`,
					`b`.`salary` as `initsalary`					
				FROM `personnels_salarys` as `a` 
				LEFT JOIN `personnels_salary_params` as `b` ON `b`.`ID`=`a`.`skill_id`
			WHERE `a`.`personnel_id`='$post_id' order by `a`.`dateup` DESC
		");
		$train = $this->Model->fetchAll("
			SELECT `a`.*,`b`.`title` as `train_level_title`
			FROM `personnels_trainings` as `a` 
			LEFT JOIN `personnels_degrees` as `b` 
				ON `a`.`train_level`=`b`.`ID`
			WHERE `a`.`personnel_id`='$post_id'
		");
		
		$work_active = $this->Model->fetchAll("
			SELECT * FROM `personnels_activities` WHERE `personnel_id`='$post_id'
		");
		$govs = $this->Model->fetchRow("SELECT `a`.* FROM `personnels_govs` as `a` WHERE `a`.`personnel_id`='$post_id'");
		
		$govacts = $this->Model->fetchAll("SELECT * FROM `personnels_govs_activities` WHERE `personnel_id`='$post_id'");
		
		$contracts = $this->Model->fetchAll("SELECT `a`.*,`b`.`title` as `type` 
			FROM `personnels_contracts` as `a` 
			LEFT JOIN `personnels_contract_types` as `b`
				ON `a`.`type_id` = `b`.`ID`
			WHERE `a`.`personnel_id`='$post_id' ORDER BY `a`.`date_reg`");
			
		$files 	   = $this->Model->fetchAll("SELECT * FROM `personnels_files` WHERE `personnel_id`='$post_id'");
		
		$this->set(array(
			general			=>	$post,
			cvs				=>	$cvs,
			salary  		=>	$salary,
			train			=>	$train,
			crwork_active	=>	$work_active,
			govs			=> 	$govs,
			govacts			=>  $govacts,
			files 			=>  $files,
			contracts		=>  $contracts
		));
		
	}

	public function deleteAction(){
		$post_id=getInt("ID",0);
		$post = $this
			->Model
			->fetchRow("SELECT * 
				FROM `personnels` 
				WHERE 
					`ID`='$post_id' 
					AND `is_draft`='no'");
			
		if(!$post){
			return $this->setJSON(array(
				alert => 'Bản ghi không tồn tại hoặc đã bị xóa trước đó'
			));
		}
		
		if( $post['photo'] ){
			@unlink("files/personnel/{$post['photo']}");
		}
		
		$files = $this->Model->fetchAll("SELECT * 
			FROM `personnels_files` 
			WHERE `personnel_id`='$post_id'");
		$this->Model->delete('personnels_files',"`personnel_id`='$post_id'");
				
		foreach( $files as $file ){
			@unlink("files/personnel/{$file['name']}");
		}
		
		
		$this->Model->delete('personnels',"`ID`='$post_id'");
		$this->Model->delete('personnels_cvs',"`personnel_id`='$post_id'");
		$this->Model->delete('personnels_salarys',"`personnel_id`='$post_id'");
		$this->Model->delete('personnels_activities',"`personnel_id`='$post_id'");
		$this->Model->delete('personnels_govs_activities',"`personnel_id`='$post_id'");
		$this->Model->delete('personnels_govs',"`personnel_id`='$post_id'");
		$this->Model->delete('personnels_contracts',"`personnel_id`='$post_id'");
		
		return $this->setJSON(array(
			redirect	=> '#Personnel'
		));
	}
	
	protected function getDepartments( $id=0, $depth = 0, $selected='', $name='personnels', $attr='' ){
		//Lay phong ban con
		$sub_departments
			= $this->Model->fetchAll("SELECT `a`.*,IF(`b`.`ID`,`b`.`ID`,0) as `parentID`
				FROM `departments` as `a`
				LEFT JOIN `departments` as `b` ON
				`a`.`parent_id`=`b`.`ID` HAVING `parentID`='$id'");


		$staffs = $this->Model->fetchAll("SELECT *,IF( '$selected' LIKE CONCAT('%,',`ID`,'%') , ' checked', '' ) as `checked`  FROM `personnels`
			WHERE `department_id`='$id' AND `is_draft`='no'");

		if(count($staffs) == 0 && count($sub_departments) == 0){
			return '';
		}

		//class
		$class = $depth == 0 ? "tree-list tree-root":"tree-list";

		$list = "<div class='tree-list-outer'>
			<div class=\"$class\">";
		foreach( $sub_departments as $k => $sub ){
			$subs = $this->getDepartments( $sub['ID'], $depth+1, $selected, $name, $attr );

			$cl = $subs !="" ? "" : " tree-link-empty";
			$cls = $subs !="" ? "" : " tree-folder-empty";

			//show child in depth
			$has_sub  = $this->Model->fetchOne("SELECT `ID` FROM `departments` WHERE `parent_id`='{$sub['ID']}'");
			$is_close = $has_sub ? "" : " tree-section-close";

			$list .="<div class='tree-folder-outer'>
				<a class='tree-node' onclick='tree_collapse(this)'></a>
				<div class='tree-folder'>
					<a class='tree-title'>{$sub['title']}</a>
					$subs
				</div></div>";
		}

		foreach( $staffs as $k => $staff ){
			$class = $staff['gender'] == 1 ? 'male' : 'female';
			$list .="<a class='tree-item-outer'>
				<span class='tree-item' title='{$staff['username']}'><span class='tree-item-icon'></span>
				<span class='$class'>{$staff['name']}</span></span>
				</a>";
		}

		$list .="</div></div>";
		return $list;
	}

	public function fileAction(){
		$file_id = get('ID',0);
		$user_id = get_user_id();

		$file = $this
			->Model->fetchRow("SELECT * FROM `personnels_files` as `a` WHERE `a`.`ID`='$file_id' LIMIT 1");

		$file_path = "files/personnel/{$file['name']}";

		if( !file_exists( $file_path ) ){
			return $this->setError('404');
		}
		if( get('type') == 'icon' ){
			$img_types = array('image/gif','image/png','image/x-png','image/jpeg','image/x-jpeg','image/jpg');
			if( in_array($file['type'],$img_types) ){
				loadClass('PHPThumb');
				$thumb = PhpThumbFactory::create($file_path);
				$thumb->resize(60, 60);
				$thumb->show();
			}else{
				@readfile("files/static/icon.gif");
			}
		}else if( get('type') == 'view' ){
			$img_types = array('image/gif','image/png','image/x-png','image/jpeg','image/x-jpeg','image/jpg');
			if( in_array($file['type'],$img_types) ){
				loadClass('PHPThumb');
				$thumb = PhpThumbFactory::create($file_path);
				$thumb->show();
			}else{
				@readfile("files/static/icon.gif");
			}
		}else{
			@header("Content-Disposition: attachment; filename={$file['name']}");
			@readfile($file_path);
		}
	}
	
	public function delgovactAction(){
		if( get('ID',0) )
		$this->Model->delete('personnels_govs_activities','`ID`="'.get('ID').'"');
		$this->setContent('');
	}	

	public function deltrainAction(){
		if( get('ID',0) )
		$this->Model->delete('personnels_trainings','`ID`="'.get('ID').'"');
		$this->setContent('');
	}	

	public function delactivityAction(){
		if( get('ID',0) )
		$this->Model->delete('personnels_activities','`ID`="'.get('ID').'"');
		$this->setContent('');
	}	
	
	public function delsalaryAction(){
		if( get('ID',0) )
		$this->Model->delete('personnels_salarys','`ID`="'.get('ID').'"');
		$this->setContent('');
	}	

	public function delcontractAction(){
		if( get('ID',0) )
		$this->Model->delete('personnels_contracts','`ID`="'.get('ID').'"');
		$this->setContent('');
	}	

	public function smsAction(){
		$this->removeLayout();
		$user_id = get_user_id();	
			
		$ids = get('ID',array(),true);
		
		if( count($ids) == 0 ){
			return $this->setJSON(array(
				alert	=> 'Chưa có bản ghi nào được chọn'
			));		
		}	
			
		$x=array();
		foreach( $ids as $k ){
			$x[] = "'$k'";
		}
		
		$x = array_unique($x);
		$x = implode(',',$x);
		
		$posts = $this->Model->fetchAll("SELECT `phone` FROM `personnels`
			WHERE `ID` IN ($x) AND `is_draft`='no'");	
		
		if( isPost() ){
			//return;
			loadClass('ZData');
			$f = new ZData();
			$f->addFields(array(
				sms_content	=> array(
					type			=> 'CHAR',
					label			=> 'Nội dung',
					max_length		=> 160,
					no_empty		=> true
				)		
			));
			
			$data = $f->getData();		
			
			if( !is_array($data) ){
				return $this->setJSON(array(
					alert	=> $data
				));
			}
			
			foreach( $posts as $post ){
				if( is_cellphone($post['phone']) ){
					sendSMS(array(
						content			=>	get('sms_content'),
						user_id			=>	$user_id,
						address			=>	$post['phone'],
						date_created	=>	new Model_Expr('NOW()'),
						date_send		=>	new Model_Expr('NOW()'),
						mode			=>	'personnel',
						post_id			=>	$post['ID']	
					),$this->Model);
				}				
			}						
			
			return $this->setJSON(array(
				close	=> true,
				alert	=> 'Tin nhắn của bạn đã được gửi di'
			));
		}
	}
	
}
?>